package rmiClient;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import util.IFatorial;

public class RMIClientFatorial {
	
	private String host;
	private String component;	
	private Object remoteFatorial;
	private IFatorial fatorial;
	
	public RMIClientFatorial() throws MalformedURLException, RemoteException, NotBoundException {
		super();
		host = "127.0.0.1";
		component = "fatorial"; // Nome no rebind do Obj remoto
		
		remoteFatorial = Naming.lookup("rmi://" + host + "/" + component);
		fatorial = (IFatorial) remoteFatorial;
	}

	public RMIClientFatorial(String host, String component) throws MalformedURLException, RemoteException, NotBoundException {
		super();
		this.host = host;
		this.component = component;
		this.remoteFatorial = Naming.lookup("rmi://" + host + "/" + component);;
		this.fatorial = (IFatorial) remoteFatorial;
	}
	
	public Integer calcRMIFatorial(int number) throws RemoteException{
		this.fatorial.send(number);
		return (Integer) this.fatorial.calc();
	}
}

